package com.nativetalk.service.study.feedback;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.study.TdNtStudyTeachComment;
import com.nativetalk.bean.study.feedback.TdNtStudyTeachFeedbackInset;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.dao.TdNtStudyTeachDao;
import com.nativetalk.dao.TdNtStudyTeachFeedbackDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Created by lizhun on 15/12/29.
 */
@Service
public class StudyTeachFeedbackServiceImpl implements  StudyTeachFeedbackService{
    private static Logger logger = Logger.getLogger(StudyTeachFeedbackServiceImpl.class);
    @Resource
    private TdNtStudyTeachDao tdNtStudyTeachDao;
    @Resource
    private TdNtStudyTeachFeedbackDao tdNtStudyTeachFeedbackDao;
    @Override
    public RetInfo inserttudyTeachFeedback(TdNtStudyTeachFeedbackInset tdNtStudyTeachFeedbackInset) {
        String logInfo = this.getClass().getName() + ":inserttudyTeachFeedback:";
        logger.info("======" + logInfo + "begin======");
        RetInfo retInfo = new RetInfo();
        try {
            TdNtStudyTeachComment tdNtStudyTeachComment = tdNtStudyTeachDao.findTdNtStudyTeachComment(tdNtStudyTeachFeedbackInset.getStt_id());
            if (tdNtStudyTeachComment != null ) {
                tdNtStudyTeachFeedbackInset.setTea_id(tdNtStudyTeachComment.getTea_id());
                tdNtStudyTeachFeedbackInset.setMemb_id(tdNtStudyTeachComment.getMemb_id());
                tdNtStudyTeachFeedbackDao.insertTdNtStudyTeachFeedback(tdNtStudyTeachFeedbackInset);
                retInfo.setMark(ValidationMessages.getValue("MARKYES"));
                retInfo.setTip("添加学习反馈成功");
            } else {
                retInfo.setMark(ValidationMessages.getValue("MARKNO"));
                retInfo.setTip(ValidationMessages.getValue("TIPAUTHORERROR"));
            }

        } catch (Exception e) {
            retInfo.setMark(ValidationMessages.getValue("MARKERROR"));
            retInfo.setTip(ValidationMessages.getValue("TIPERROR"));
            logger.error(e.getMessage(),e);
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
